﻿using System.Reflection;

using Tszy.Unlimited.Base.Infrastructure.SlideCaptcha.Resources.Handler;

namespace Tszy.Unlimited.Base.Infrastructure.SlideCaptcha.Resources.Provider
{
    public class EmbeddedResourceProvider : IResourceProvider
    {
        private const int DEFAULT_TEMPLATE_COUNT = 5;

        public List<SlideCaptchaResource> Backgrounds()
        {
            return new List<SlideCaptchaResource>();
        }

        public List<SlideCaptchaTemplatePair> Templates()
        {
            var templatePairs = new List<SlideCaptchaTemplatePair>();

            var assembly = Assembly.GetExecutingAssembly();
            var names = assembly.GetManifestResourceNames().ToList();

            for (var i = 0; i < DEFAULT_TEMPLATE_COUNT; i++)
            {
                var sliderResourceName = $"Tszy.Unlimited.Base.Infrastructure.SlideCaptcha.Templates._{i + 1}.slider.png";
                var holeResourceName = $"Tszy.Unlimited.Base.Infrastructure.SlideCaptcha.Templates._{i + 1}.hole.png";

                var sliderResource = new SlideCaptchaResource(EmbeddedResourceHandler.TYPE, sliderResourceName);
                var holeResource = new SlideCaptchaResource(EmbeddedResourceHandler.TYPE, holeResourceName);
                templatePairs.Add(SlideCaptchaTemplatePair.Create(sliderResource, holeResource));
            }

            return templatePairs;
        }
    }
}